package com.ruoyi.quartz.util;

import cn.hutool.http.HttpException;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;

import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

/**
 * @author TsingYu
 * @version 1.0
 * @date 2025/8/18 16:21
 */
public class QBTuUtil {

    // static  final String CY_GET_DATA_URL =  "192.168.8.251:8086/qbt/api/553036673260679053754558";
    // static  final String CY_GET_DATA_URL =  "http://qbttmeter.com:8086/qbt/api/ydfsc";
     static  final String CY_GET_DATA_URL =  "http://qbttmeter.com:8086/qbt/api/GDQTHJ";
    // static  final String CY_GET_DATA_URL =  "http://qbttmeter.com:8086/qbt/api/jsssswyxgs";
    static  final String USER_NO =  "GDQTHJ";
    static  final String USER_PW =  "GDqt147!#$";
    static  final String MY_KEY =  "553036673260679053754558";

    public static String GetDeviceData() {
        Map<String, Object> params = new HashMap<>();
        try {
        String data =  USER_NO+"-"+USER_PW+"-" +  System.currentTimeMillis() ;
        params.put("data",DesUtil.encodeByECBToBase64( MY_KEY.getBytes(StandardCharsets.UTF_8)
                ,data.getBytes(StandardCharsets.UTF_8))
                .replace("+","%2B"));

            return HttpUtil.post(CY_GET_DATA_URL, params, 10 * 1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    public static void main(String[] args) {
         JSONObject jsonObject = JSON.parseObject(GetDeviceData());
        System.out.println(jsonObject.toString());

        String  data  = jsonObject.getString("data");
        try {
            System.out.println(DesUtil.decodeByECBToString(MY_KEY, data));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
